﻿/**
* Title:"项目";
*
* Description:
*        功能：
*
* Author:Tongwel
*
* Date:2018.6
*
* Modify:
*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace DemoSpace
{
    //view显示的一个模型
    public class PackItem : MonoBehaviour
    {
        Text countText;
        Image img;
        private void Awake()
        {
            this.countText = this.transform.Find("Text").GetComponent<Text>();
            this.img = this.transform.Find("GoodImg").GetComponent<Image>();
        }
        private PackModel model;

        //用属性来处理预制体的信息
        //（当数量为零图片隐藏 不为零 从模型提取数据）
        public PackModel Model
        {
            get { return model; }
            set {
                if (model.GoodCount != 0)
                {
                    this.img.enabled = true;
                    this.img.sprite = Resources.Load<Sprite>(model.goodModel.Src);
                    this.countText.text = model.GoodCount.ToString();
                }
                else
                {
                    this.img.enabled = false;
                    this.countText.text = "0";
                    this.img.sprite = null;
                }
            }
        }
    }
}